/**********************************************************************************
// DirectDrawGame Header File
//
// Creation:	19 May 2007
// Updated:		30 Set 2009
// Compiler:	Visual Studio 2008
//
// Notes:		A DirectDrawGame is a WindowsGame that makes use of DirectDraw
//				functions to access the video card aceleration hardware.
//
**********************************************************************************/

#ifndef _ANABELE_DIRECTDRAWGAME_H_
#define _ANABELE_DIRECTDRAWGAME_H_

/**********************************************************************************/

// Defines
#define INITGUID			// make sure directX guids are included

// Includes
#include <ddraw.h>			// include DirectDraw stuff
#include "WindowsGame.h"	// WindowsGame class definition
#include "Color.h"			// Color class definition

/**********************************************************************************/

// Global Constants and Enumerations
enum Buffering {SINGLEBUFFERING=1, DOUBLEBUFFERING=2, TRIPLEBUFFERING=3};
enum Fps {FIXED30FPS=1, VARIABLEFPS=2};


/**********************************************************************************/

class DLL DirectDrawGame : public WindowsGame
{
private:
	LPDIRECTDRAWSURFACE7	lpDDSPrimary;			// interface pointer to primary surface
	LPDIRECTDRAWSURFACE7	lpDDSBack;				// interface pointer to back buffer
	DDSURFACEDESC2			ddSD;					// the DirectDraw surface description
	DDBLTFX ddBltFx;								// used for background color fill

	int						fpsMode;				// fps mode = FIXED30FPS or VARIABLEFPS
	DWORD					coopLevel;				// cooperation level control flags
	int						refreshRate;			// display refresh rate
	int						screenBpp;				// screen color depth
	int						buffering;				// SINGLEBUFFERING, DOUBLEBUFFERING or TRIPLEBUFFERING

protected:
	LPDIRECTDRAW7			lpDD;					// interface pointer to directdraw object
	LPDIRECTDRAWSURFACE7	lpDDSDisplay;			// pointer to primary surface or back buffer

	int						memoryPitch;			// bytes in each line of Video RAM
	UINT *					videoRAM;				// pointer to Video RAM (32bpp mode)

	void ClearScreen();								// clear the screen with background color
	void PageFlip();								// flip back and primary buffers

public:
	DirectDrawGame();								// DirectDrawGame Constructor
	~DirectDrawGame();								// DirectDrawGame Destructor

	// DirectDraw methods
	void SetFramePerSec(int mode);					// set fixed or variable FPS, default is fixed to 30FPS 
	void SetRefreshRate(int dwRefreshRate);			// set the screen refresh rate, default is 60Hz
	void SetBuffering(int level);					// set buffering mode, default is DOUBLEBUFFERING
	void LockScreen();								// lock the screen for exclusive access to the video ram
	void UnLockScreen();							// unlock the screen to free video ram access to others

	// overriden methods from WindowsGame
	void SetWindowMode(int mode);							// set window mode to FULLSCREEN or WINDOWED
	void SetWindowBgColor(int r, int g, int b);				// set window bakground color using DirectDraw
	int  Text(char *text, int x, int y, COLORREF color);	// draw text using Windows GDI - slow
	bool Initialize(HINSTANCE appInstance);					// initialize window and directdraw surfaces
	int  Start();											// start the game loop
};

/**********************************************************************************/

// InLine Member Functions

// DirectDraw methods

// set fixed or variable FPS, default is fixed to 30FPS
inline void DirectDrawGame::SetFramePerSec(int mode)
{ fpsMode = mode; }

// set the screen refresh rate, default is 60Hz
inline void DirectDrawGame::SetRefreshRate(int dwRefreshRate)
{ refreshRate = dwRefreshRate; }

// set buffering mode, default is DOUBLEBUFFERING
inline void DirectDrawGame::SetBuffering(int level)
{ buffering = level; }

// set window bakground color using DirectDraw
inline void DirectDrawGame::SetWindowBgColor(int r, int g, int b)
{ ddBltFx.dwFillColor = Color(r,g,b).Encoded(); }

/**********************************************************************************/

#endif